package com.cl.base.timer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.temporal.ChronoField;

@Component
@Slf4j
@EnableScheduling
public class AppTask {

    @Scheduled(cron = "0 0 0/1 * * ? ")
//    @Scheduled(cron = "0/2 * * * * ? ")
    public void nowTime() {
        LocalDateTime now = LocalDateTime.now();
        int year = now.get(ChronoField.YEAR);
        int month = now.get(ChronoField.MONTH_OF_YEAR);
        int day = now.get(ChronoField.DAY_OF_MONTH);
        int hour = now.get(ChronoField.HOUR_OF_DAY);
        int minute = now.get(ChronoField.MINUTE_OF_HOUR);
        int second = now.get(ChronoField.SECOND_OF_MINUTE);
        int milli = now.get(ChronoField.MILLI_OF_SECOND);
        log.info("{}年{}月{}日 {}时{}分{}秒{}毫秒", year, month, day, hour, minute, second, milli);
    }
}
